Big O notation describes the performance or complexity of an algorithm. so it indicates the time and memory a code will take to execute, the best case is reaching log(n) since it takes the least time and space
the orders of the big O Notation are:
it describes the case when code will executes in the same time and space no matter what’s the inputs (constant), example:
def fact2(n):
if n == 0:
return 1
else:
return n * fact2(n-1)
print (fact2(5))
O(N) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. for example:
def fact(n):
product = 1
for i in range(n):
product = product * (i+1)
return product
print (fact(5))
O(N²) represents an algorithm whose performance is directly proportional to the square of the size of the input data set. example:
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for i in a:
for x in a:
print("x")
O(2^N) denotes an algorithm whose growth doubles with each addition to the input data set. Example
int Fibonacci(int number)
{
if (number <= 1) return number;
return Fibonacci(number - 2) + Fibonacci(number - 1); `}`
This type of algorithm is described as O(log N). The iterative halving of data sets described in the binary search example produces a growth curve that peaks at the beginning and slowly flattens out as the size of the data sets increase
the graph below summarizes the oreders of the big O notation:
## Pain vs. Suffering
always remember through this pain these questions: